package me.algo;

import java.util.Comparator;
import java.util.Objects;

/**
 * @author guozheng
 * @date 2024/3/23
 */
public class Sorts {


    public static void main(String[] args) {
        Integer[] arr = new Integer[]{1, 32, 4, 5, 21, 3, 52, 10};
        selectSort(arr);
        System.out.println(arr);
    }

    public static void selectSort(Integer[] array) {
        new SelectSort<Integer>().sort(array);
    }


    private static class SelectSort<T extends Comparable<T>> implements Sort<T> {

        @Override
        public void sort(T[] array) {
            if (Objects.isNull(array) || array.length <= 1) {
                return;
            }
            for (int i = 0; i < array.length; i++) {
                for (int j = i; j < array.length; j++) {
                    if (!less(array[i],array[j])) {
                        exch(array, i, j);
                    }
                }
            }
        }
    }
}
